package com.jekun.helloworld.designmode.composite.demo03;

import javax.swing.*;
import java.awt.*;


public class Login {
    private JFrame frame = new JFrame("登录");
    private Container container = frame.getContentPane();
    private JTextField username = new JTextField();
    private JPasswordField password = new JPasswordField();
    private JButton ok = new JButton("确定");
    private JButton cancel = new JButton("取消");

    public Login() {
        frame.setSize(300, 200);
        container.setLayout(new BorderLayout());
        initFrame();
        frame.setVisible(true);
        frame.setLocationRelativeTo(null);
    }

    private void initFrame() {
//顶部
        JPanel titlePanel = new JPanel();
        titlePanel.setLayout(new FlowLayout());
        titlePanel.add(new JLabel("系统管理员登录"));
        container.add(titlePanel, "North");

//中部表单
        JPanel fieldPanel = new JPanel();
        fieldPanel.setLayout(null);
        JLabel a1 = new JLabel("用户名:");
        a1.setBounds(50, 20, 50, 20);
        JLabel a2 = new JLabel("密  码:");
        a2.setBounds(50, 60, 50, 20);
        fieldPanel.add(a1);
        fieldPanel.add(a2);
        username.setBounds(110, 20, 120, 20);
        password.setBounds(110, 60, 120, 20);
        fieldPanel.add(username);
        fieldPanel.add(password);
        container.add(fieldPanel, "Center");

//底部按钮
        JPanel buttonPanel = new JPanel();
        buttonPanel.setLayout(new FlowLayout());
        buttonPanel.add(ok);
        buttonPanel.add(cancel);
        container.add(buttonPanel, "South");
    }

    public static void main(String[] args) {
        new Login();
    }
}